<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Func_Permit extends CI_Controller
{
    protected $_templates;
	
    function __construct()
	{
		parent::__construct();
		$this->pre_message = "";
		$this->load->model('func_permit_model','func_permit');
		$this->permit_library->check_permit();
		$this->session->set_userdata(array('Url'=>uri_string()));           
    }   
	    
    function showlist()
	{
        $data['cat'] = $this->func_permit->get_permission_by_id();
		$data['add'] = 'func_permit/add/'.(int)$this->uri->segment(3) ;
        $data['title'] = 'Danh sách chức năng Modules '.$data['cat']->permission_name; 
        $data['list'] = $this->func_permit->get_list_func_by_permit($this->uri->segment(3)); 
        $data['num'] = count($data['list']);
        $this->_templates['page'] = 'permission/func/list';
        $this->site->load($this->_templates['page'],$data);
    }
       
	function add()
	{
		$data['title'] = 'Thêm mới Modules';
		$data['list'] = $this->func_permit->get_all_permission();
		if(!empty($_POST['bt_submit']))
		{
			$this->form_validation->set_rules('function_name','Tên chức năng','trim|required');  
			$this->form_validation->set_rules('function_notice','Ghi chú','');  
			if($this->form_validation->run() == FALSE){
				$this->pre_message = validation_errors();
			}else{
				if($this->func_permit->save())
				{
					$this->session->set_flashdata('message','Lưu thành công');
					redirect('func_permit/showlist/'.$this->uri->segment(3));
				}else{
					$this->pre_message = 'Lưu không thành công';
				}
			} 
		}
		$data['message'] = $this->pre_message;          
		$this->_templates['page'] = 'permission/func/add';
		$this->site->load($this->_templates['page'],$data);
	}
      
      
      function edit()
	  {
          $data['title'] = 'Cập nhật Modules';
          $data['list'] = $this->func_permit->get_all_permission();
          $data['rs'] = $this->func_permit->get_func_by_id($this->uri->segment(4));
          if(!empty($_POST['bt_submit']))
		  {
             $this->form_validation->set_rules('function_name','Tên chức năng','trim|required');  
             $this->form_validation->set_rules('function_notice','Ghi chú','');  
             if($this->form_validation->run() == FALSE){
                $this->pre_message = validation_errors();
             }else{
                 if($this->func_permit->save()){
                     $this->session->set_flashdata('message','Lưu thành công');
                     redirect('func_permit/showlist/'.$this->uri->segment(3));
                 }else{
                     $this->pre_message = 'Lưu không thành công';
                 }
             } 
          }
          $data['message'] = $this->pre_message;          
          $this->_templates['page'] = 'permission/func/edit';
          $this->site->load($this->_templates['page'],$data);
      }       
}
?>
